package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.mapper.UserMapper;
import com.itheima.pojo.entity.PageBean;
import com.itheima.pojo.entity.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**更新
     * @param user
     */
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    /**
     * 分页查询
     * @param pageCondition
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageBean<User> findPageUser(String pageCondition, Long pageNum, Long pageSize) {

        //使用mybatis分页插件,注入页码和页面大小
        PageHelper.startPage(pageNum.intValue(),pageSize.intValue());

        //传入搜索条件查询页面数据
        List<User> users=userMapper.findPageUser(pageCondition);

        //注入到分页插件中
        PageInfo<User> userPageInfo = new PageInfo<>(users);

        PageBean<User> userPageBean = new PageBean<User>();

        userPageBean.setList(userPageInfo.getList());
        userPageBean.setTotal(userPageInfo.getTotal());

        return userPageBean;
    }
}
